﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using FineUI;
using SDLITS.Model;
using SDLITS.Common;

namespace SDLITS.Web.SystemManage
{
    public partial class MasterDicManage : CommonBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                BindData();
            }
        }
        protected void BindData()
        {
            MasterDic item = SDDbSession.Default.From<MasterDic>().ToFirstDefault();
            if (item != null)
            {
                txt_bkfy.Text = item.InitialAmount.ToString();
                txt_bksxf.Text = item.WorkAmount.ToString();
                txt_df.Text = item.ElecPrice.ToString();
                txt_dy.Text = item.PrintPrice.ToString();
                dt_dfdq.Text = item.ElecEndDate;
                dt_dftx.Text = item.ElecReminderDate;
                dt_zldq.Text = item.RentEndDate;
                dt_zltx.Text = item.RentRemiderDate;
            }
        }
        protected void btnSaveRefresh_Click(object sender, EventArgs e)
        {
            MasterDic item = new MasterDic();
            int returnvalue = 0;
            try
            {
                item.MasterDicID = 1;
                item.Attach();
                item.ElecEndDate = dt_dfdq.Text;
                item.ElecPrice = decimal.Parse(txt_df.Text);
                item.ElecReminderDate = dt_dftx.Text;
                item.InitialAmount = decimal.Parse(txt_bkfy.Text);
                item.PrintPrice = decimal.Parse(txt_dy.Text);
                item.RentEndDate = dt_zldq.Text;
                item.RentRemiderDate = dt_zltx.Text;
                item.WorkAmount = decimal.Parse(txt_bksxf.Text);
                returnvalue = SDDbSession.Default.Update<MasterDic>(item);
            }
            catch (Exception)
            {
                item.DeAttach();
                item.ElecEndDate = dt_dfdq.Text;
                item.ElecPrice = decimal.Parse(txt_df.Text);
                item.ElecReminderDate = dt_dftx.Text;
                item.InitialAmount = decimal.Parse(txt_bkfy.Text);
                item.PrintPrice = decimal.Parse(txt_dy.Text);
                item.RentEndDate = dt_zldq.Text;
                item.RentRemiderDate = dt_zltx.Text;
                item.WorkAmount = decimal.Parse(txt_bksxf.Text);
                returnvalue = SDDbSession.Default.Insert<MasterDic>(item);
            }
            if (returnvalue > 0)
            {
                Alert.Show("修改成功！");
            }
        }
    }
}